package com.ideaplugin.datamanager.common;

import com.ideaplugin.datamanager.model.common.PageRequest;
import com.ideaplugin.datamanager.model.common.PageResult;
import com.mybatisflex.core.paginate.Page;

/**
 * Created on 2023/6/13.
 *
 * @author zhaojb
 */
public class PageUtil {

    public static <T> PageResult<T> convert(Page<T> page) {
        PageResult<T> pageResult = new PageResult();
        pageResult.setPage(page.getPageNumber());
        pageResult.setPageSize((int) page.getPageSize());
        pageResult.setTotal(page.getTotalRow());
        pageResult.setData(page.getRecords());
        return pageResult;
    }

    public static Page convert(PageRequest.PageBase pageBase) {
        return Page.of(pageBase.getPageIndex(), pageBase.getPageSize());
    }

    public static Page convert(PageRequest pageRequest) {
        return convert(pageRequest.getPage());
    }

}
